/**
 * 
 */
package at.ac.lbg.media.vis.framework.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @author Evelyn Münster
 *
 */
@Entity
@Table(name = "taxonomy")
public class CategoryDO implements Comparable<CategoryDO>
{
	
	@Id
	private Long id;
	
	@Column
	private String name;
	
	@Column
	private int sorting;
	
	@Column
    private int level;
	
	@ManyToOne(cascade = CascadeType.ALL, optional = true)
	@JoinColumn(name = "parentid")
	private CategoryDO parentCategory;

    @Column(nullable=true)
	private Integer countartworks;
	
	
	@Transient
	private List<CategoryDO> children = new ArrayList<CategoryDO>();

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the parentCategory
	 */
	public CategoryDO getParentCategory() {
		return parentCategory;
	}

	/**
	 * @param parentCategory the parentCategory to set
	 */
	public void setParentCategory(CategoryDO parentCategory) {
		this.parentCategory = parentCategory;
	}
	
	

	public List<CategoryDO> getChildren() {
		return children;
	}

	public void setChildren(List<CategoryDO> children) {
		this.children = children;
	}

	public int getSorting() {
		return sorting;
	}

	public void setSorting(int sorting) {
		this.sorting = sorting;
	}

	@Override
	public int compareTo(CategoryDO cat2) {
		if (this.id < cat2.id) {
			return -1;
		} else if (this.id > cat2.id) {
			return 1;
		}
		return 0;
	}

    public Integer getCountartworks() {
        return countartworks;
    }

    public void setCountartworks(Integer countartworks) {
        this.countartworks = countartworks;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }
	

}
